
<div class='page-header'>
    当前位置：<span class="text-primary">任务设置</span>
</div>
<style type="text/css">
    #calendar .header {

        width: 840px;
        height: 40px;
        margin-bottom: 40px;

    }

    #calendar .weeks {
        border-bottom: 1px solid #ccc;
        width: 840px;
        height: 40px;
        line-height: 40px;
        background: #f2f2f2;
    }

    #calendar .weeks .col-sm-2 {
        width: 120px;
        font-weight: bold;
        text-align: center;
    }

    #calendar .dates {
        width: 840px;
        height: 120px;
        text-align: center;

    }

    #calendar .dates .col-sm-2 {
        position: relative;
        width: 120px;
        height: 120px;
        text-align: center;
        background: #fefefe;
        line-height: 110px;
        border: 1px solid #f2f2f2;
    }


    #calendar .dates .col-sm-2 .btn {
        margin: 0;

        color:#fff;
        overflow: hidden;

        -ms-word-break: break-all;
        word-break: break-all;
        word-wrap: break-word;
        white-space:normal;

        max-height:50px;
        background:#f2f2f2;
        color:#333;

    }
    #calendar .dates .col-sm-2 .btn.btn-set-has {
        background: #00aeff;
        color:#fff;
    }
    #calendar .dates .col-sm-2 .date{
        position:absolute;
        right:0;top:5px;
        font-size:14px;
        color:#999;
        line-height:20px;
        display:inline-block;width:20px;height:20px;
    }
    #calendar .dates .col-sm-2 .link{
        position:absolute;
        right:0;bottom:5px;
        font-size:14px;
        color:#666;
        line-height:20px;
        text-align: center;
        display:inline-block;width:120px;height:20px;
        display: none;

    }

    #loading {
        width:100%;
        padding:20px 0;
        text-align: center;;
    }

    #calendar .dates .col-sm-2.select {
        /*background:#fefdeb;*/
    }
    #calendar .dates .col-sm-2 a {
        color:#666;
    }
</style>
<div class="page-content">
<div class="row">

    <div class="col-sm-12">
        <div id="calendar">
            <div class="header">
                <div>
                      <!--  <label for="" style="vertical-align: sub">批量设置:</label>-->
                    <label class="checkbox-inline">
                        <input type="checkbox"  value="all" checked /> 全月
                    </label>     <label class="checkbox-inline" >
                    <input type="checkbox"  value="1" checked /> 周一
                </label>
                    <label class="checkbox-inline" style="">
                        <input type="checkbox"  value="2" checked /> 周二
                    </label>   <label class="checkbox-inline" style="">
                    <input type="checkbox"  value="3" checked /> 周三
                </label>   <label class="checkbox-inline" style="">
                    <input type="checkbox"  value="4" checked /> 周四
                </label>   <label class="checkbox-inline" style="">
                    <input type="checkbox"  value="5"  checked/> 周五
                </label>   <label class="checkbox-inline" style="">
                    <input type="checkbox"  value="6" checked /> 周六
                </label>   <label class="checkbox-inline" style="">
                    <input type="checkbox"  value="7" checked /> 周日
                </label>
                    <span class=" pull-right">
                            <select class="form-control" style="width:100px;display:inline-block;" ng-model="pagedata.currentyear"  id="year">  
                                <option  ng-repeat="y in pagedata.years" value="{{y}}"  ng-select="pagedata.currentyear==y">{{y}}</option>
                            </select>
                                    年
                            <select class="form-control" style="width:100px;display:inline-block;" ng-model="pagedata.currentmonth" id="month"> 
                                <option ng-repeat="m in  pagedata.months" value="{{m}}"  ng-select="pagedata.currentmonth==m" >{{m}}</option>
                            </select>
                                    月
                        </span>
                </div>
               <!--     <div class="input-group">
                        <a href="javascript:;" class="btn btn-default btn-sm btn-batch-set" style="display:inline-block;margin:10px 5px">批量设置</a>
                        <a href="javascript:;" class="btn btn-default btn-sm btn-batch-delete" style="display:inline-block;margin:10px 5px">批量取消</a>
                        <a href="javascript:;" class="btn btn-default btn-sm btn-clear" style="display:inline-block;margin:10px 5px">清空当月</a>
                    </div> -->
            </div>
            <div class="weeks">
                <div class="col-sm-2">日</div>
                <div class="col-sm-2">一</div>
                <div class="col-sm-2">二</div>
                <div class="col-sm-2">三</div>
                <div class="col-sm-2">四</div>
                <div class="col-sm-2">五</div>
                <div class="col-sm-2">六</div>
            </div>
            <div id="loading"><i class="fa fa-spinner fa-spin"></i> 正在加载数据</div>
			<div class="dates">
				<div ng-repeat="item in pagedata.kongday" class="col-sm-2 date-item ">
					<div class="date"></div>
					<a>
						<div>
						空
						</div>
						
					</a>
				</div>
				<div ng-repeat="(k,c) in pagedata.calendar" class="col-sm-2 date-item " ng-class="{'select':c!=null && c!=''}" date="{{k}}" taskid="{{c.taskid}}">
					<div class="date">{{pagedata.d[k]}}</div>
					<div class="link"  style="display:none">
						<a ng-click="access_josn('jy_seckill/task/edit/id='+c.taskid)" target="_blank" data-href="{php echo webUrl('seckill/task/edit')}" class="btn-edit" title="编辑秒杀">
							<i class="icon icon-edit"></i></a>

						<a ng-click="access_josn('jy_seckill/good//taskid='+c.taskid)" target="_blank" data-href="{php echo webUrl('seckill/goods')}" class="btn-goods"  title="查看商品">
							<i class="icon icon-goods"></i></a>
						<a href="javascript:;" class="btn-delete" title="取消"><i class="icon icon-delete"></i></a>
					</div>
					<a href="javascript:;" class="btn btn-set" ng-class="{'btn-set-has':c!='' && c!=null}" >
						<div ng-if="c=='' || c==null">
						选择
						</div>
						<div ng-if="c!='' && c!=null">
						{{c.taskid}}{{c.title}}
						</div>
						
					</a>
				</div>
			</div>
        </div>
    </div>
</div>
</div>
<script language="javascript">
    function getDates(){
		year = $('#year').val();
        month = $('#month').val();
		scope.get('jy_seckill/calendar/dates/year='+year+'&month='+month,function(res){
			scope.pagedata.week=res.week;
			scope.pagedata.kongday=res.kongday;
			$('#loading').hide();
			scope.$evalAsync();
			bindEvents();
		});
    }
    var currentDate = null;
    function bindEvents(){
        $('.btn-set').click(function(){
            var btn = $(this);
            var item = btn.closest('.date-item');
            currentDate = item.attr('date');
		//
			//var url= ROOT_D+'/manage/index.php?plugin=jy_seckill&action=task&op=query';
			//var url2= ROOT_D+'/manage/index.php?plugin=jy_seckill&action=calendar&op=set';
			scope.modal_func(function(data){				
                    var taskid = data;
					var params = {
					'plugin':'jy_seckill',
					'action':'calendar',
					'op':'set',
					'data':{taskid: taskid , date: currentDate},
					'callback':function(ret){
							if(ret.status==1){
                                btn.addClass('btn-set-has').html( "[" + taskid + "]"+ ret.result.title + "");
                                item.attr('taskid',taskid).addClass('select').find('.link').show();
                                var btngoods = item.find('.btn-goods');
                                btngoods.attr('href' , btngoods.data('href') + "&taskid=" + taskid);

                                var btnedit = item.find('.btn-edit');
                                btnedit.attr('href' , btnedit.data('href') + "&id=" + taskid);
                                bindHover();
                                return;
                            }
                            //alert(ret.taskid);
						}								
					}
				scope.post_json(params);
                   /* $.ajax({
                        url: url2,
                        data: {taskid: taskid , date: currentDate},
                        dataType:'json',
                        type:'POST',
                        success:function(ret){
                            if(ret.status==1){
                                btn.addClass('btn-set-has').html( "[" + taskid + "]"+ ret.result.title + "");
                                item.attr('taskid',taskid).addClass('select').find('.link').show();
                                var btngoods = item.find('.btn-goods');
                                btngoods.attr('href' , btngoods.data('href') + "&taskid=" + taskid);

                                var btnedit = item.find('.btn-edit');
                                btnedit.attr('href' , btnedit.data('href') + "&id=" + taskid);
                                bindHover();
                                return;
                            }
                            tip.msgbox.err(ret.result.message);
                        }
                    });*/
                },'','jy_seckill/get_task/');
           /* biz.selector_open.select({
                'name': 'task_set',
                'readonly': true,
                'url':url,
                'nokeywords':1,
                'autosearch':1,
                'placeholder':'请输入秒杀标题',
                'callback':function(data,obj){

                    var taskid = data.id;
                    $.ajax({
                        url: url2,
                        data: {taskid: taskid , date: currentDate},
                        dataType:'json',
                        type:'POST',
                        success:function(ret){
                            if(ret.status==1){
                                btn.addClass('btn-set-has').html( "[" + taskid + "]"+ ret.result.title + "");
                                item.attr('taskid',taskid).addClass('select').find('.link').show();
                                var btngoods = item.find('.btn-goods');
                                btngoods.attr('href' , btngoods.data('href') + "&taskid=" + taskid);

                                var btnedit = item.find('.btn-edit');
                                btnedit.attr('href' , btnedit.data('href') + "&id=" + taskid);
                                bindHover();
                                return;
                            }
                            tip.msgbox.err(ret.result.message);
                        }
                    });
                }
            });*/
        });

        $('.btn-delete').click(function(){
            var btn = $(this);
			//var url3= ROOT_D+'/manage/index.php?plugin=jy_seckill&action=calendar&op=delete';
            var item = btn.closest('.date-item');
            currentDate = item.attr('date');
			scope.confirm({
				'message':'确认取消 ' + currentDate + " 的秒杀?",
				'success':function(){
				btn.button('loading');
				var params = {
					'plugin':'jy_seckill',
					'action':'calendar',
					'op':'delete',
					'data': {date: currentDate},
					'callback':function(ret){
							console.log(ret);
							item.find('.btn-set').html('选择');
							btn.button('reset'),item.attr('taskid','').find('.link').hide();
							item.find('.btn-set').removeClass('btn-set-has');
							bindHover();
							scope.message('删除成功！');
						}								
					}
					scope.post_json(params);
				},
				'fail':function(){}
			});
        });
        bindHover();
    }

    function bindHover(){
        $('.date-item').unbind('mouseover').mouseover(function(){
            if( $(this).attr('taskid')){
                $(this).find('.link').show();
            }else{
                $(this).find('.link').hide();
            }
        }).unbind('mouseout').mouseout(function(){
            $(this).find('.link').hide();

        })
    }
    $(function(){
        getDates();
        $('#year,#month').change(function(){
            getDates();
        });
        $(':checkbox').click(function(){
            var val  =$(this).val();
            var checked = $(this).prop('checked');
            if(val=='all'){
                $(':checkbox').prop('checked',checked);
            }else{
                if( !checked){
                    $(':checkbox[value="all"]').prop('checked',false);
                }
            }
        });
        $('.btn-clear').click(function(){
            var btn = $(this);
            year = $('#year').val();
            month = $('#month').val();
			scope.confirm({
				'message':'确认要清空 ' + month + "年" + month+"月份的秒杀吗?",
				'success':function(){
					btn.button('loading');
					var params = {
						'plugin':'jy_seckill',
						'action':'calendar',
						'op':'clear',
						'data': { year: year,month:month},
						'callback':function(ret){
								btn.button('reset');
								$('.date-item').each(function(){
									var obj = $(this);
									obj.removeClass('select').attr('taskid','');
									obj.find('.link').hide(),obj.find('.btn-set').removeClass('btn-set-has').html('选择');
								});
								bindHover();
								scope.message('清空成功！');
							}								
						}
					scope.post_json(params);
				}
			});
		});
        $('.btn-batch-set').click(function(){
            var btn = $(this);
            var days = $(':checkbox:checked').map(function () {
                return $(this).val()
            }).get();

            year = $('#year').val();
            month = $('#month').val();
			//var url4= ROOT_D+'/manage/index.php?plugin=jy_seckill&action=task&op=query';
			scope.modal_func(function(data){
                    var taskid = data;
					var params = {
						'plugin':'jy_seckill',
						'action':'calendar',
						'op':'batch_set',
						'data':{taskid: taskid , year:year,month:month, days: days},
						'callback':function(ret){
							if(ret.status==1){
                                $('.date-item').each(function(){

                                    var item = $(this),btn = item.find('.btn-set');
                                    if( ret.result.dates.indexOf(item.attr('date'))!=-1){

                                        btn.addClass('btn-set-has').html( "[" + taskid + "]"+ ret.result.title );
                                        item.attr('taskid',taskid).addClass('select').find('.link').show();
                                        var btngoods = item.find('.btn-goods');
                                        btngoods.attr('href' , btngoods.data('href') + "&taskid=" + taskid);

                                        var btnedit = item.find('.btn-edit');
                                        btnedit.attr('href' , btnedit.data('href') + "&id=" + taskid);
                                    }

                                });
                                bindHover();
                                return;
                            }
                           // tip.msgbox.err(ret.result.message);
						}								
					}
		
				scope.post_json(params);
                   /* $.ajax({
                        url: "{php echo webUrl('seckill/calendar/batch_set')}",
                        data: {taskid: taskid , year:year,month:month, days: days},
                        dataType:'json',
                        type:'POST',
                        success:function(ret){
                            if(ret.status==1){
                                $('.date-item').each(function(){

                                    var item = $(this),btn = item.find('.btn-set');
                                    if( ret.result.dates.indexOf(item.attr('date'))!=-1){

                                        btn.addClass('btn-set-has').html( "[" + taskid + "]"+ ret.result.title );
                                        item.attr('taskid',taskid).addClass('select').find('.link').show();
                                        var btngoods = item.find('.btn-goods');
                                        btngoods.attr('href' , btngoods.data('href') + "&taskid=" + taskid);

                                        var btnedit = item.find('.btn-edit');
                                        btnedit.attr('href' , btnedit.data('href') + "&id=" + taskid);
                                    }

                                });
                                bindHover();
                                return;
                            }
                            tip.msgbox.err(ret.result.message);
                        }
                    });*/
                },'','jy_seckill/get_task/');
           /* biz.selector_open.select({
                'name': 'task_batch_set',
                'readonly': true,
                'url':url4,
                'nokeywords':1,
                'autosearch':1,
                'placeholder':'请输入秒杀标题',
                'callback':function(data,obj){
				
                    var taskid = data.id;
					
					
            });*/
        });


        $('.btn-batch-delete').click(function(){
            var btn = $(this);
			//var url6= ROOT_D+'/manage/index.php?plugin=jy_seckill&action=calendar&op=batch_set';
            var days = $(':checkbox:checked').map(function () {
                return $(this).val()
            }).get();

            year = $('#year').val();
            month = $('#month').val();
            tip.confirm('确认要取消这些日期的秒杀吗?',function(){
			
				var params = {
					'plugin':'jy_seckill',
					'action':'calendar',
					'op':'batch_set',
					'data': {year:year,month:month, days: days},
					'callback':function(ret){
							if(ret.status==1){
                            $('.date-item').each(function(){

                                var item = $(this),btn = item.find('.btn-set');
                                if( ret.result.dates.indexOf(item.attr('date'))!=-1){
                                    item.removeClass('select').attr('taskid','');
                                    item.find('.link').hide(),item.find('.btn-set').removeClass('btn-set-has').html('选择');
                                }

                            });
                            bindHover();
                            return;
                        }
                       // tip.msgbox.err(ret.result.message);
						}								
					}
		
				scope.post_json(params);
               /* $.ajax({
                    url: url6,
                    data: {year:year,month:month, days: days},
                    dataType:'json',
                    type:'POST',
                    success:function(ret){
                        if(ret.status==1){
                            $('.date-item').each(function(){

                                var item = $(this),btn = item.find('.btn-set');
                                if( ret.result.dates.indexOf(item.attr('date'))!=-1){
                                    item.removeClass('select').attr('taskid','');
                                    item.find('.link').hide(),item.find('.btn-set').removeClass('btn-set-has').html('选择');
                                }

                            });
                            bindHover();
                            return;
                        }
                        tip.msgbox.err(ret.result.message);
                    }
                });*/
            });
        });
    })
</script>
